using System.Web.Mvc;
using LogikBug.ModularMvc;
using LogikBug.ModularMvc.Navigation;
using LogikBug.ModularMvc.Registration;

namespace Test.Modules.Messaging
{
	public class MessagingModule : VisualModule
	{
		#region Constructors

		public MessagingModule()
		{
			Name = "Messaging";
			OrderPrecedence = 10.0m;
			MenuDisplayOrder = 2;
			IsOptional = true;
		}

		#endregion

		#region Methods

		#region ModuleBase Members

		protected override void Initialize(IRegistrationContext context)
		{
			context.Routes.MapRoute(
				this,
				"MessagingMailRoute",
				"mail/{action}/view/{folderName}",
				new { controller = "mail", action = "folder", folderName = "inbox" },
				new[] { "Test.Modules.Messaging.Controllers" }
			);

			context.Routes.MapRoute(
				this,
				"MessagingAjaxRoute",
				"ajax/{action}/mail",
				new { controller = "ajax", action = "messagingsubnavigation" },
				new[] { "Test.Modules.Messaging.Controllers" }
			);

			context.Routes.MapRoute(
				this,
				"MessagingDefaultRoute",
				"mail/{action}/{id}",
				new { controller = "mail", action = "inbox", id = UrlParameter.Optional },
				new[] { "Test.Modules.Messaging.Controllers" }
			);
		}

		#endregion

		#region VisualModuleBase Members

		public override MenuItemCollection GetMenu(ViewContext viewContext, MenuType menuType)
		{
			if (menuType == MenuType.Main)
			{
				var url = new UrlHelper(viewContext.RequestContext);

				return new MenuItemCollection
				{
					new MenuItem("#", "Mail")
					{
						CssClass = "ddHeaderSubNav",
						Data = url.RouteUrl("MessagingAjaxRoute", new
						{
						    controller = "ajax",
							action = "messagingsubnavigation"
						})
					}
				};
			}

			return null;
		}

		#endregion

		#endregion
	}
}